package top.scsoul.pas.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.scsoul.pas.entity.Role;
import top.scsoul.pas.repository.RoleRepository;
import top.scsoul.pas.service.RoleService;

import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.List;
@Transactional(rollbackOn = Exception.class)
@Slf4j
@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    RoleRepository repository;

    @Override
    public List<Role> roleList() {
        return repository.findAll();
    }

    @Override
    public Role getRoleById(Long id) {
        return repository.getById(id);
    }

    @Override
    public List<Role> getRoleByIds(List<Long> ids) {
        ArrayList<Role> list = new ArrayList<>();
        ids.forEach(id -> {
            Role role = repository.getById(id);
            list.add(role);
        });
        return list;
    }
}
